﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Graph
{
    internal const int MaxNode = 1024;
    private List<int>[] childNodes;
    private List<int> bfsPath;

    public Graph(List<int>[] childNodes)
    {
        this.childNodes = childNodes;
        this.bfsPath = new List<int>();
    }

    public List<int> BFSPath
    {
        get { return bfsPath; }
    }

    public void TraverseBFS(int node)
    {
        bool[] visited = new bool[MaxNode];
        Queue<int> queue = new Queue<int>();
        queue.Enqueue(node);
        visited[node] = true;
        while (queue.Count > 0)
        {
            int currentNode = queue.Dequeue();
            bfsPath.Add(currentNode);
            foreach (int childNode in childNodes[currentNode])
            {
                if (!visited[childNode])
                {
                    queue.Enqueue(childNode);
                    visited[childNode] = true;
                }
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Graph g = new Graph(ReadGraph());

        g.TraverseBFS(0);

        PrintResult(g.BFSPath);
    }

    static List<int>[] ReadGraph()
    {
        // Read number of nodes N
        string input = Console.ReadLine();
        int N = int.Parse(input);

        // Read graph as adjacency list
        List<int>[] graph = new List<int>[N];

        for (int i = 0; i < N; i++)
        {
            graph[i] = new List<int>();

            input = Console.ReadLine();
            string[] childs = input.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var child in childs)
            {
                graph[i].Add(int.Parse(child));
            }
        }

        return graph;
    }

    static void PrintResult(List<int> path)
    {
        // Print result path in format {start node1 node2 ... end}
        StringBuilder builder = new StringBuilder(path.Count * 2);

        for (int i = 0; i < path.Count; i++)
        {
            if (i < path.Count - 1)
            {
                builder.Append(String.Format("{0} ", path[i]));
            }
            else
            {
                builder.Append(path[i]);
            }
        }

        Console.WriteLine(builder);
    }
}